package com.qike.duola.utils;

import io.jsonwebtoken.Claims;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;
import org.gavaghan.geodesy.Ellipsoid;
import org.gavaghan.geodesy.GeodeticCalculator;
import org.gavaghan.geodesy.GeodeticCurve;
import org.gavaghan.geodesy.GlobalCoordinates;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.mobile.device.Device;
import org.springframework.stereotype.Component;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

@Component
public final class DistanceUtil {


    /**
     * 根据两个地址的经纬度获取距离
     * @param projectLat
     * @param projectLng
     * @param planLat
     * @param planLng
     * @return
     */
    public static Double getDistance(Double projectLat,Double projectLng,Double planLat,Double planLng) {
        GlobalCoordinates source = new GlobalCoordinates(projectLat, projectLng);
        GlobalCoordinates target = new GlobalCoordinates(planLat, planLng);

        double meter1 = getDistanceMeter(source, target, Ellipsoid.Sphere);
        return meter1;
    }

    public static double getDistanceMeter(GlobalCoordinates gpsFrom, GlobalCoordinates gpsTo, Ellipsoid ellipsoid){

        //创建GeodeticCalculator，调用计算方法，传入坐标系、经纬度用于计算距离
        GeodeticCurve geoCurve = new GeodeticCalculator().calculateGeodeticCurve(ellipsoid, gpsFrom, gpsTo);

        return geoCurve.getEllipsoidalDistance();
    }
}
